import { route, GET, POST } from 'awilix-express';

@route('/logos')
export default class LogosApi {

  constructor({ logosService }) {
    this.logosService = logosService;
  }

  @route('/getLogosAll')
  @POST()
  async getLogosAll(req, res){
    const {
      mark
    } = req.body
    const { success, data: list, message } = await this.logosService.getLogosAll({mark});
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message, list);
  }

  @route('/getLogoslist')
  @POST()
  async getLogosList(req, res) {
    const { AGENT_USERNAME, mark, limit, offset } = req.body
    const { success, data: {count, rows}, message } = await this.logosService.getLogosList({AGENT_USERNAME, mark, limit, offset});
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message, {count, rows});
  }

  @route('/addLogos')
  @POST()
  async addLogos(req, res) {
    const { 
      AGENT_USERNAME,
      AGENT_PASSWORD,
      AGENT_PHONE,
      AGENT_EMAIL,
      mark
     } = req.body;
    const { success, message } = await this.logosService.addLogos({
      AGENT_USERNAME,
      AGENT_PASSWORD,
      AGENT_PHONE,
      AGENT_EMAIL,
      mark
    });
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }

  @route('/delLogos')
  @POST()
  async delLogos(req, res) {
    const { id, mark } = req.body;
    const { success, message } = await this.logosService.delLogos({id, mark});
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }


  @route('/updateLogos')
  @POST()
  async updateLogos(req, res) {
    const {
      id,
      AGENT_USERNAME,
      AGENT_PASSWORD,
      AGENT_PHONE,
      AGENT_EMAIL,
      mark
    } = req.body;
    const { success, message } = await this.logosService.updateLogos({
      id,
      AGENT_USERNAME,
      AGENT_PASSWORD,
      AGENT_PHONE,
      AGENT_EMAIL,
      mark
    });
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }
}